package com.example.demo.jpa.customer;

import com.example.demo.jpa.customer.dto.CustomerCommand;
import com.example.demo.jpa.customer.dto.CustomerDTO;
import com.example.demo.jpa.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @GetMapping("/{id}")
    public CustomerDTO getCustomerById(@PathVariable Long id){
        return customerService.findCustomerByID(id);
    }
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public CustomerDTO createCustomer(@RequestBody CustomerCommand customerCommand ){
        return customerService.createCustomer(customerCommand);
    }
    @PutMapping("/{id}")
    public CustomerDTO updateCustomer(@PathVariable Long id,@RequestBody CustomerCommand customerCommand){
        return  customerService.updateCustomer(id,customerCommand);
    }
    @DeleteMapping("/{id}")
    public ResponseEntity  deleteCustomer(@PathVariable Long id){
        customerService.deleteCustomerById(id);
        return ResponseEntity.ok().build();
    }
}





